package com.yidu.t299.controller.twj;

import com.yidu.t299.contant.CommonConstant;
import com.yidu.t299.domain.twj.SysRole;
import com.yidu.t299.service.twj.SysRoleBiz;
import com.yidu.t299.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author twj
 * @version 1.0.0
 */

@RestController
public class SysRoleController {
    @Autowired
    private SysRoleBiz sysRoleBiz;

    /**
     * 新增
     */
    @PostMapping("sysRole/add")
    public Result add(@RequestBody SysRole sysRole) {
        sysRoleBiz.insert(sysRole);
        return Result.success();
    }

    /**
     * 编辑
     */
    @PutMapping("sysRole/edit")
    public Result edit(@RequestBody SysRole sysRole) {
        sysRoleBiz.update(sysRole);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("sysRole/remove/{roleId}")
    public Result remove(@PathVariable Integer roleId) {
        sysRoleBiz.deleteByPrimaryKey(roleId);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("sysRole/remove")
    public Result removeBatch(Integer[] array) {
        sysRoleBiz.deleteBatch(array);
        return Result.success();
    }

    /**
     * 单条查询
     */
    @GetMapping("sysRole/find/{roleId}")
    public Result findById(@PathVariable Integer roleId) {
        return Result.success(sysRoleBiz.selectById(roleId));
    }

    /**
     * 分页查询
     */
    @GetMapping("sysRole/findPage")
    public Result findPage(@RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
                           @RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
                           SysRole sysRole) {
        return Result.success(sysRoleBiz.findPage(pageNum, pageSize, sysRole));
    }

    /**
     * 查询
     */
    @GetMapping("sysRole/find")
    public Result find(SysRole sysRole) {
        return Result.success(sysRoleBiz.select(sysRole));
    }

}
